/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package tanqueDeAgua;

/**
 *
 * @author pabloramix
 */
public class Tank {
    
    private double capacity;
    private double content;

    public Tank (double litres) {
        this.capacity = litres;
        this.content = 0;
    }
    
    /**
     * @return the capacity
     */
    public double getCapacity() {
        return capacity;
    }

    /**
     * @param capacity the capacity to set
     */
    private void setCapacity(double capacity) {
        this.capacity = capacity;
    }

    /**
     * @return the level
     */
    public double getContent() {
        return content;
    }

    /**
     * @param level the level to set
     */
    private void setContent(double level) {
        this.content = level;
    }
    
    public long getLevel() {
        
        return (long) Math.floor((Math.min(capacity, content)/capacity) * 100);
    }
    
    public synchronized void fill (double litres) {
        
        if (content + litres <= 0) {
            content = 0;
        } else if (content + litres >= capacity * 1.01) {
            content = capacity * 1.01;
        } else {
            content += litres;
        }
    }
}
